package com.xidian.zhiancloud.controller.emergencyManagement;

import com.xidian.zhiancloud.controller.base.BaseController;
import com.xidian.zhiancloud.dto.ResultDTO;
import com.xidian.zhiancloud.dto.emergencyManagement.EmergencyPlanManagementDTO;
import com.xidian.zhiancloud.enums.GeneralResponseEnums;
import com.xidian.zhiancloud.model.ReviewRecord;
import com.xidian.zhiancloud.model.RevisionRecord;
import com.xidian.zhiancloud.service.emergencyManagement.RevisionRecordService;
import com.xidian.zhiancloud.vo.emergencyManagement.RevisionRecordVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.Date;
import java.util.List;
/**
 * 应急管理 应急预案管理接口-修订记录
 */
@RestController
@RequestMapping("/RevisionRecord")
public class RevisionRecordController extends BaseController {

    @Autowired
    private RevisionRecordService revisionRecordService;

    /**
     * 增加修订记录
     *
     * @param revisionRecord 修订记录对象
     * @return 返回是否添加成功
     */
    @PostMapping("/add")
    public ResultDTO<Boolean> add(RevisionRecord revisionRecord) {
        revisionRecord.setCreateTime(new Date(System.currentTimeMillis()));
        revisionRecord.setCreatorId(getSessionUserid());
        revisionRecord.setCompanyId(getSessionUserCompanyId());
        Boolean res=revisionRecordService.save(revisionRecord);
        return ResultDTO.successOf(res,GeneralResponseEnums.SUCCESS);
    }

    /**
     * 根据id删除修订记录
     *
     * @param ids ids数组
     * @return 返回是否删除成功
     */
    @PostMapping("/deleteByIds")
    public ResultDTO<Boolean> deleteByIds(Long[] ids) {

        return ResultDTO.successOf(revisionRecordService.removeByIds(Arrays.asList(ids)), GeneralResponseEnums.SUCCESS);
    }

    /**
     * 根据id修改修订记录对象
     *
     * @param revisionRecord 修订记录
     * @return 返回是否修改成功
     */
    @PostMapping("/patchById")
    public ResultDTO<Boolean> patchById(RevisionRecord revisionRecord) {
        revisionRecord.setCreateTime(null);
        revisionRecord.setCompanyId(null);
        revisionRecord.setCreatorId(null);
        return ResultDTO.successOf(revisionRecordService.updateById(revisionRecord), GeneralResponseEnums.SUCCESS);
    }

    /**
     * 根据id获取修订记录
     *
     * @param id 修订记录对象的id
     * @return 修订对象
     */
    @GetMapping("/getList")
    public ResultDTO<List<RevisionRecordVO>> getRevisionRecord(@RequestParam("id") Long id) {
        return ResultDTO.successOf(revisionRecordService.getList(id), GeneralResponseEnums.SUCCESS);
    }
}
